﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="dokumendid", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(Dokumendid))]
    public class DokumendidSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDokumendid clazz;
        
        public DokumendidSerializer(IDokumendid clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.TYHIVASTUS!=null) {
                Writer.WriteStartElement("TYHIVASTUS");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TYHIVASTUS))).ToString());
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.DOKUMENT != null) 
                        && (x < clazz.DOKUMENT.Count)); x = (x + 1)) {
                if (clazz.DOKUMENT[x]!=null) {
                    Writer.WriteStartElement("DOKUMENT");
                    global::Xtee.Core.SerializationMetadata metaDOKUMENT = this.GetMetaData(clazz.DOKUMENT[x]);
                    Writer.WriteTypeAttribute(metaDOKUMENT.TypeQualifiedName.Namespace, metaDOKUMENT.TypeQualifiedName.Name);
                    metaDOKUMENT.NewSerializer(clazz.DOKUMENT[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="TYHIVASTUS") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumendid>TYHIVASTUS");
                }
                clazz.TYHIVASTUS = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("TYHIVASTUS")).Value;
            }
            if (Reader.LocalName=="DOKUMENT") {
                clazz.DOKUMENT = new System.Collections.Generic.List<Dokumendid.IDOKUMENTType>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "DOKUMENT")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumendid>DOKUMENT");
                    }
                    global::Xtee.Core.SerializationMetadata metaDOKUMENT = this.GetMetaData<Dokumendid.IDOKUMENTType>(Reader, ">>dokumendid>DOKUMENT", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                    Dokumendid.IDOKUMENTType item = metaDOKUMENT.NewEntity<Dokumendid.IDOKUMENTType>();
                    clazz.DOKUMENT.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("DOKUMENT");
                        metaDOKUMENT.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>dokumendid>DOKUMENT", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(Dokumendid.DOKUMENTType))]
        public class DOKUMENTTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Dokumendid.IDOKUMENTType clazz;
            
            public DOKUMENTTypeSerializer(Dokumendid.IDOKUMENTType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (clazz.DOKNR!=null) {
                    Writer.WriteStartElement("DOK_NR");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DOKNR))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DOKKP!=null) {
                    Writer.WriteStartElement("DOK_KP");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DOKKP))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DOKUMENT!=null) {
                    Writer.WriteStartElement("DOKUMENT");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DOKUMENT))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DOKUMENDIVALJASTAJA!=null) {
                    Writer.WriteStartElement("DOKUMENDI_VALJASTAJA");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DOKUMENDIVALJASTAJA))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.DATA!=null) {
                    Writer.WriteStartElement("DATA");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DATA))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.BuildingURL!=null) {
                    Writer.WriteStartElement("buildingURL");
                    Writer.WriteTypeAttribute("http://x-tee.riik.ee/xsd/xtee.xsd", "url");
                    Writer.WriteString(clazz.BuildingURL.ToString());
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="DOK_NR") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>dokumendid>DOKUMENT>DOK_NR");
                    }
                    clazz.DOKNR = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DOK_NR")).Value;
                }
                if (Reader.LocalName=="DOK_KP") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>dokumendid>DOKUMENT>DOK_KP");
                    }
                    clazz.DOKKP = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DOK_KP")).Value;
                }
                if (Reader.LocalName=="DOKUMENT") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>dokumendid>DOKUMENT>DOKUMENT");
                    }
                    clazz.DOKUMENT = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DOKUMENT")).Value;
                }
                if (Reader.LocalName=="DOKUMENDI_VALJASTAJA") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>dokumendid>DOKUMENT>DOKUMENDI_VALJASTAJA");
                    }
                    clazz.DOKUMENDIVALJASTAJA = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DOKUMENDI_VALJASTAJA")).Value;
                }
                if (Reader.LocalName=="DATA") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>dokumendid>DOKUMENT>DATA");
                    }
                    clazz.DATA = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("DATA")).Value;
                }
                if (Reader.LocalName=="buildingURL") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>dokumendid>DOKUMENT>buildingURL");
                    }
                    clazz.BuildingURL = new global::Xtee.Riik.Ee.Xsd.Xtee.Url(Reader.ReadElementString("buildingURL"));
                }
            }
        }
    }
}
